package com.zc.auth.security.core.authentication;

import com.zc.commons.user.dto.AuthorizedUser;
import io.jsonwebtoken.Claims;

/**
 * 用户token解析
 *
 * @author zcj
 * @version 1.0.0
 * @date 2022/1/13 11:10
 */
public class JwtParseService implements AuthenticationTokenService<AuthorizedUser> {

    private JsonWebTokenService jsonWebTokenService;

    public JwtParseService(JsonWebTokenService jsonWebTokenService) {
        this.jsonWebTokenService = jsonWebTokenService;
    }

    @Override
    public Class<AuthorizedUser> getSupportedClass() {
        return AuthorizedUser.class;
    }

    @Override
    public String getTokenJson(String token) {
        Claims body = jsonWebTokenService.getTokenBody(token);
        return body.get(jsonWebTokenService.getUserClaims(), String.class);
    }
}
